package com.woniu.woniu_bx.mapper;

import com.woniu.woniu_bx.pojo.Img;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName GoodsImg
 * @Description 商品图片Mapper
 * @Author 魏才林
 * @Date 2022/8/29 17:30
 * @Version 1.0
 **/
@Repository
public interface GoodsImgMapper {

    @Insert({"<script>" +
            "insert into bx_goods_img(goods_id,url) values" +
            "<foreach collection='goodsImgs' item='img' separator=','>" +
            "(#{img.relationalId},#{img.url})" +
            "</foreach>" +
            "</script>"})
    void insert(List<Img> goodsImgs);

    @Delete({"<script>" +
            "delete from bx_goods_img where id in" +
            "<foreach collection='ids' item='id'  open='('  separator=','  close=')'>" +
            "#{id}" +
            "</foreach>" +
            "and goods_id =#{goodsId}" +
            "</script>"})
    void delete(@Param("ids") List<Integer> ids, @Param("goodsId") Integer goodsId);

    @Select("select * from bx_goods_img where goods_id=#{goodsId}")
    @Results(
            id = "GoodsImgMapper",
            value = {
                    @Result(column = "id", property = "id", id = true),
                    @Result(column = "goods_id", property = "relationalId"),
                    @Result(column = "url", property = "url")
            }
    )
    List<Img> getAllImgByGoodsId(Integer goodsId);
}
